<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

<style>
	.mar-l200 {margin-left: 200px;}
</style>
</head>
<body>
<div id="app" class="content-div">
    <div class="panel panel-default">
		<form id="defaultFormUser" class="form-horizontal" enctype="multipart/form-data">
			<div class="form-box">
				<input type="hidden" name="id" v-model="sysUserInfo.id">
				<input type="hidden" name="userId" v-model="sysUserInfo.userId">											    						
				<div class="form-group">
				     	<div class="col-sm-2 control-label mar-l200">公众号appID</div>
				     	<div class="col-sm-5">
		              		<input type="text" class="input-small form-control" name="appid" v-model="sysUserInfo.appid" placeholder="公众号appID"/>
		                </div>
		                <!-- <input id="validateBtn" type="button" class="btn btn-primary" @click="checkAppid"  value="校验"/> -->
		         </div>
		    						
				<div class="form-group">
				     	<div class="col-sm-2 control-label mar-l200">公众号APPSECRET</div>
				     	<div class="col-sm-5">
		              		<input type="text" class="input-small form-control" name="appsecret" v-model="sysUserInfo.appsecret" placeholder="公众号APPSECRET"/>
		                </div>
		         </div>
		    						
				<div class="form-group">
				     	<div class="col-sm-2 control-label mar-l200">公众号TOKEN</div>
				     	<div class="col-sm-5">
		              		<input type="text" class="input-small form-control" name="token" v-model="sysUserInfo.token" placeholder="公众号TOKEN"/>
		                </div>
		         </div>
		    						
				<div class="form-group">
				     	<div class="col-sm-2 control-label mar-l200">商户号mchid</div>
				     	<div class="col-sm-5">
		              		<input type="text" class="input-small form-control" name="mchid" v-model="sysUserInfo.mchid" placeholder="商户号mchid"/>
		                </div>
		         </div>
		    						
				<div class="form-group">
				     	<div class="col-sm-2 control-label mar-l200">支付密钥apikey</div>
				     	<div class="col-sm-5">
		              		<input type="text" class="input-small form-control" name="apikey" v-model="sysUserInfo.apikey" placeholder="支付密钥apikey"/>
		                </div>
		         </div>
		    						
				<div class="form-group" id="urlDiv">
				     	<div class="col-sm-2 control-label	mar-l200">支付证书地址</div>
				     	<div class="col-sm-5">
		              		<input type="text" class="input-small form-control" name="url" readonly v-model="sysUserInfo.url" placeholder="支付证书地址"/>		              		
		                </div>
		         </div>	
		         <div class="form-group">
				     	<div class="col-sm-2 control-label	mar-l200">上传证书</div>
		                <div class="col-sm-5">
		                	<input type="file" name="file" id="file-yy" multiple="multiple" class="file-loading"/>
		                </div>
		         </div>
	         </div>
		</form>
    </div>
	<!-- 编辑内容显示区间 end -->
	    
</div>

<script>

$(function() {
	$.get($path+"sys/sysuserinfo/info/"+userId, function(r){
		if(r.sysUserInfo == null){
			vm1.sysUserInfo = {};
			$("#urlDiv").hide();
			canSave = false;					

		}else{
			vm1.sysUserInfo = r.sysUserInfo;
			userInfo = vm1.sysUserInfo;
			$("#urlDiv").show();
			canSave = true;
			
		}
		hasClient = false;
    });

});

var vm1 = new Vue({
	el:'#app',
	data:{
		sysUserInfo: {
		}		       
	},
	methods: {
		getUserInfo:function(userId){
			$.get($path+"sys/sysuserinfo/info/"+userId, function(r){
				if(r.sysUserInfo == null){
					vm1.sysUserInfo = {};
				}else{
					vm1.sysUserInfo = r.sysUserInfo;
				}
				
            });
		}
	}
});
$('#defaultFormUser').bootstrapValidator({
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
    		appid: {
	            message: 'The appid is not valid',
	            validators: {
	                notEmpty: {
	                    message: 'appid不能为空！'
	                },
	                regexp:{
	                	regexp : /^[^ ]+$/, 
	                	message:'输入不能有空格'
	                },
	                remote: {
				        url: $path+'sys/sysuserinfo/checkAppid',
				        message: '该公众号未授权或者授权失效或者存在审核通过的投放',
				        delay :  500,
				        type: 'GET',
				        dataType: "json",
				        data:{				        	
				        	appid:function(){
				        		return vm1.sysUserInfo.appid;
				        	},
				        	sysUserInfoId:function(){
				        		var sysUserId;
				        		if(vm1.sysUserInfo.id == undefined){
				        			sysUserId = '';
				        		}else{
				        			sysUserId = vm1.sysUserInfo.id;
				        		}
				        		return sysUserId;
				        	}
				        }  
				    }
	            }
	        },
	        appsecret: {
	            message: 'The appsecret is not valid',
	            validators: {
	                notEmpty: {
	                    message: 'appsecret不能为空！'
	                }
	            }
	        },
	        token: {
	            message: 'The token is not valid',
	            validators: {
	                notEmpty: {
	                    message: 'token不能为空！'
	                }
	            }
	        },
	        mchid: {
	            message: 'The mchid is not valid',
	            validators: {
	                notEmpty: {
	                    message: 'mchid不能为空！'
	                }
	            }
	        },
	        apikey: {
	            message: 'The apikey is not valid',
	            validators: {
	                notEmpty: {
	                    message: 'apikey不能为空！'
	                }
	            }
	        }

    }
});

//此证书的上传地址为微信系统
var uploadTool = $("#file-yy").fileinput({
	locales : "zh",
	uploadUrl: WX_SERVER+'/tool/uploadMultipleFile?username='+vm.user.username+"&companyNo="+vm.user.companyNo,
	autoReplace : true,
	uploadAsync: false,
	showUpload: true,
	showPreview: true,
	showRemove : true, //显示移除按钮
	maxFileCount: 1,
	showClose:false,
	dropZoneEnabled: false,
	allowedFileExtensions:['p12'],
	maxFileSize : 524288, //512M
	singleFileUploads: false,
	layoutTemplates:{
		actionDelete:'',
		actionUpload:''
	}
}).on('filecleared' , function(){
	//发送请求删除文件
	canSave = false;
}).on('filebrowse' , function(){
	$("#file-yy").fileinput('clear');
}).on('fileloaded',function(){
	$("#urlDiv").hide();
	console.log("wechat:"+WX_SERVER+'/tool/uploadMultipleFile?username='+vm.user.username+"&companyNo="+vm.user.companyNo);
	canSave = true;
	console.log("上传证书响应===========" + canSave);
	hasClient = true;
}).on('filebatchuploadsuccess ',function(event, data, previewId, index){
	vm1.sysUserInfo.url = data.response.path;
	console.log("vm1.sysUserInfo.url is:"+vm1.sysUserInfo.url)
});



</script>
</body>
</html>